home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Mac OS Development Toolkit / Automation Essentials 2.3.0 / Host Automation Folder / SPEC Libs / Select.Lib < prev    next >
Encoding:
Text File  |  1998-03-19  |  13.8 KB  |  363 lines  |  [TEXT/MPS ]

  1. #
  2. # ****************************************************************************
  3. #
  4. #    File Name:        Select.Lib
  5. #
  6. #    Contains:    xxx put contents here xxx
  7. #
  8. #    Written by:    KTA, KL, ML, GS et al
  9. #
  10. #    Copyright:    © 1993-1996 by Apple Computer, Inc., all rights reserved.
  11. #
  12. # ****************************************************************************
  13. #            C h a n g e        H i s t o r y (most recent first):
  14. # ****************************************************************************
  15. #
  16. #        Vers      Date        Author        Description
  17. #        ----    --------    ------    ---------------------------------------------
  18. #     <1.0.9>      2/8/96    JC        Changed all window .r (Rect) traits to .b (bound) traits and
  19. #                                    changed any window insets to reflect new bound rect.
  20. #     <1.0.8>     1/19/95    KTA        Changed the name of ExceptionHandler() to ExceptionDispatcher().
  21. #     <1.0.7>    12/12/94    ML        Replaced gLoglevel w/gDisableAllLogging
  22. #     <1.0.6>     12/5/94    ML        Added exception handling support
  23. #     <1.0.5>     3/24/94    KTA        Changed the name of RandomSelection() to RandomTextSelection().
  24. #     <1.0.4>     3/24/94    KTA        Added task RandomTextSelection() - which can be used for randomly
  25. #                                    selecting text.
  26. #     <1.0.3>     12/2/93    KTA        PointSelect() now reports that it performs a click.
  27. #        <1+>     5/21/93    NAGA        Adding header and porting old files to follow new standards
  28. #
  29. # ****************************************************************************
  30. #
  31.  
  32. ########################################################################
  33. #                            External libraries 
  34. #=======================================================================
  35. Libraries "UserInterface.Lib", "Output.Lib", "Geometry.Lib",
  36. "ExceptionHandling.Lib";
  37.  
  38. #########################################################################
  39. #                            SelectModule.vu
  40. #========================================================================
  41. # Description:    This module contains VU code for selecting items.
  42. #                All of the Tasks in this module assume that the select
  43. #                tool has already been selected.  The library Tasks in
  44. #                this module are grouped in the following logical order:
  45. #
  46. #                SelectIt(ProcID,PtorRect)
  47. #                PointSelect(Pt,RelToWindow)
  48. #                RectSelect(Rect,RelToWindow)
  49. #                HereToStartSelect()
  50. #                HereToEndSelect()
  51. #                SelectAll()
  52. #
  53. #     Copyright Apple Computer, Inc. 1985-1990
  54. #    All rights reserved
  55. #
  56. #========================================================================
  57. # History:
  58. #
  59. #########################################################################
  60.  
  61.  
  62. #########################################################################
  63. #                            SelectIt(ProcID,PtorRect)
  64. #========================================================================
  65. # Author:            SMQ 
  66. #
  67. # Description:        This routine performs multiple selection tests :
  68. #
  69. #                    #1    Selects a point.
  70. #                    #2    Selects everything within a rectangle.
  71. #                    #3    Selects everything from the current position to the 
  72. #                        top of the file.
  73. #                    #4    Selects everything from the current position to the
  74. #                        bottom of the file.
  75. #                    #5    Selects the entire file, i.e. everything from the
  76. #                        top of the file to the bottom.
  77. #
  78. # Parameters:        ProcID - holds the procedure number
  79. #                    PtorRect - holds Pt or Rect coordinates
  80. #
  81. # Returns:            0 - encountered an input error. ProcID not one of the choices or
  82. #                        format of the PtorRect has an incorrect number of elements.
  83. #
  84. # Examples:            SelectIt(3,PtorRect)
  85. #
  86. # Assumptions:        Ruler is not shown
  87. #========================================================================
  88. # History:
  89. #
  90. #########################################################################
  91. TASK SelectIt(ProcID,PtorRect) begin
  92.  
  93. # Point is a list of 2 numbers which gives the x-y coordinates of the point
  94. # Rect is a list of 4 numbers which gives the left, top, right and bottom coordinates of the rect
  95.  
  96.     if (card(PtorRect) = 4) begin         # PtorRect is a list of 4 numbers
  97.         xcoord := PtorRect[1];            # just for this test, take first 2 numbers as the point coords.
  98.         ycoord := PtorRect[2];
  99.         Point:= {xcoord,ycoord};
  100.         Rect := PtorRect;
  101.     end;
  102.     else if (not (card(PtorRect) = 2) or (card(PtorRect) = 4)) begin        # PtorRect not a Point or a Rect
  103.         println 'PtorRect must be either a list of 2 numbers (in the case of a point) or';
  104.         println ' a list of 4 numbers (in the case of a rectangle)';
  105.         return (0);
  106.     end;
  107.     
  108.     # Select a Task according to the ProcID
  109.     if (ProcID = 1) begin
  110.         PointSelect (Point);                
  111.     end;
  112.     else if (ProcID = 2) begin
  113.         RectSelect (Rect);                       
  114.     end;
  115.     else if (ProcID = 3) begin
  116.         HereToStartSelect ();
  117.     end;
  118.     else if (ProcID = 4) begin
  119.         HereToEndSelect ();
  120.     end;
  121.     else if (ProcID = 5) begin
  122.         SelectAll ();
  123.     end;
  124.     else begin
  125.         println ProcID, ' is not one of the choices';    
  126.         return (0);
  127.     end;
  128. end;
  129.  
  130. #########################################################################
  131. #            PointSelect (pPointList,pRelToWindow, pSpecifier)
  132. #========================================================================
  133. # Author:            SMQ
  134. # Description:        This routine moves the mouse to the location specified
  135. #                    by pPointList and clicks to select the point. 
  136. # Parameters:        pPointList - List - holds the x-y coordinates of the point
  137. #                    pRelToWindow - 1 - coords are relative to the window
  138. #                                  0 - coords are absolutes, with respect 
  139. #                                        to the screen.
  140. #                    pSpecifier - Enables caller to specify the window the move 
  141. #                                 will be relative to. (0 = document window)
  142. # Returns:            what MoveRelativeToWindow() or MoveMouse() return
  143. # Examples:            PointSelect ({120,100},1, 0)
  144. # Assumptions:        
  145. #========================================================================
  146. # History:
  147. # KTA    12/1/93    Changed calls to MoveRelativeToWindow(), MoveMouse() so they
  148. #                can handle logging the click (bug # 1121663)
  149. # KTA    12/1/93 Added pSpecifier input parameter and return value and changed
  150. #                the name of the paramters.
  151. #########################################################################
  152. TASK PointSelect (pPointList,pRelToWindow := 1, pSpecifier := 1) 
  153. begin
  154.     returnVal := 0;                # Init ReturnVal
  155.     if (pRelToWindow)            # Relative To window
  156.         returnVal := MoveRelativeToWindow (pPointList[1],pPointList[2],pSpecifier,2);
  157.     else                        # Absolute coordinates
  158.         returnVal := MoveMouse (pPointList[1],pPointList[2],1,2);
  159.     
  160.     return(returnVal);        
  161. end;
  162.  
  163. #########################################################################
  164. #                    RectSelect (Rect,RelToWindow)
  165. #========================================================================
  166. # Author:            SMQ
  167. # Description:        This routine selects the rectangle specified by Rect.
  168. #                    It moves the mouse to the location specified by the
  169. #                    first 2 elements in Rect and everything up to the 
  170. #                    location specified by the next 2 elements.
  171. # Parameters:        Rect - holds the left, top, right and bottom 
  172. #                            coordinates of the rect.
  173. #                    RelToWindow - 1 - coords are relative to the window
  174. #                                  0 - coords are absolutes, with respect 
  175. #                                        to the screen.
  176. # Returns:            Nothing
  177. # Examples:            RectSelect (Rect,1)
  178. # Assumptions:        Ruler is not shown
  179. #========================================================================
  180. # History:
  181. # ML    11/29/94    Added Exception Handling support
  182. #########################################################################
  183. TASK RectSelect (Rect,RelToWindow := 1) begin
  184.     prev_speed := mouseSpeed(5);            # slow down the mouse and save previous mouse speed
  185.     if (RelToWindow = 1) begin
  186.         MoveRelativeToWIndow (Rect[1],Rect[2],1);
  187.         _click();
  188.         MoveMouse (Rect[3]-Rect[1],Rect[4]-Rect[2],0,1);
  189.     end;
  190.     else begin                                # Relative to screen as opposed to window
  191.         MoveMouse (Rect[1],Rect[2],1,0);
  192.         _click();
  193.         MoveMouse (Rect[3],Rect[4],1,1);
  194.     end;
  195.     mouseSpeed(prev_speed);                    # reset the mouse speed to original
  196. end;
  197.  
  198. #########################################################################
  199. #                            HereToStartSelect()
  200. #========================================================================
  201. # Author:            SMQ
  202. # Description:        This routine selects everything from the current 
  203. #                    position to the start (Top) of the file.
  204. # Parameters:        None
  205. # Returns:            Nothing
  206. # Examples:            HereToStartSelect()
  207. # Assumptions:        Ruler is not shown, coordinates used are relative 
  208. #                    to the window, as opposed to the screen.
  209. #========================================================================
  210. # History:
  211. # ML    11/29/94    Added Exception Handling support
  212. #########################################################################
  213. TASK HereToStartSelect() begin
  214.     ScrollBarList := GetVHScrollBars();        # Save current position of scrollbar
  215.     Vertical := ScrollBarList[1].s;
  216.     
  217.     Vertical_X := Vertical[1];
  218.     Vertical_Y := Vertical[2];
  219.  
  220.     ScrollWindow('V',0,1);                    # Scroll to the top of file
  221.     
  222.     _pressKey ({ shiftKey });                # Select from current position to top of file
  223.     MoveRelativeToWindow (5,30,1);
  224.     _click();
  225.     _releaseKey ({ shiftKey });
  226.     
  227.     ScrollWindow('V',Vertical_X,Vertical_Y);    # Scroll back to original position
  228. end;
  229.  
  230. #########################################################################
  231. #                            HereToEndSelect()
  232. #========================================================================
  233. # Author:            SMQ
  234. # Description:        This routine selects everything from the current 
  235. #                    position to the end (Bottom) of the file.
  236. # Parameters:        None
  237. # Returns:            Nothing
  238. # Examples:            HereToEndSelect()
  239. # Assumptions:        Ruler is not shown, coordinates used are relative 
  240. #                    to the window, as opposed to the screen.
  241. #========================================================================
  242. # History:
  243. # ML    11/29/94    Added Exception Handling support
  244. # JC      2/6/96    Changed "try match [window o:1 r:?Rect]" to "try match [window o:1 b:?Rect]"
  245. #########################################################################
  246. TASK HereToEndSelect() begin
  247.     ScrollBarList := GetVHScrollBars();            # Save current position of scrollbar
  248.     Vertical := ScrollBarList[1].s;
  249.     
  250.     Vertical_X := Vertical[1];
  251.     Vertical_Y := Vertical[2];
  252.     
  253.     ScrollWindow('V',1,1);                        # Scroll to the bottom of file
  254.     
  255.     _pressKey ({ shiftKey });                    # Select from current position to bottom of file
  256.     try match [window o:1 b:?Rect];
  257.     catch theError
  258.         ExceptionDispatcher(theError);
  259.     MoveRelativeToWindow (Rect[3]-Rect[1]-20,Rect[4]-Rect[2]-30,1);
  260.     _click();
  261.     _releaseKey ({ shiftKey });
  262.     
  263.     ScrollWindow('V',Vertical_X,Vertical_Y);    # Scroll back to original position
  264. end;
  265.  
  266. #########################################################################
  267. #                            SelectAll()
  268. #========================================================================
  269. # Author:            SMQ
  270. # Description:        This routine selects everything from the top of the
  271. #                    frontmost window to the bottom.
  272. # Parameters:        None
  273. # Returns:            Nothing
  274. # Examples:            SelectAll()
  275. # Assumptions:        Ruler is not shown, coordinates used are relative 
  276. #                    to the window, as opposed to the screen.
  277. #========================================================================
  278. # History:
  279. # ML    11/29/94    Added Exception Handling support
  280. # JC      2/6/96    Changed "try match [window o:1 r:?Rect]" to "try match [window o:1 b:?Rect]"
  281. #########################################################################
  282. TASK SelectAll() begin
  283.  
  284.     # see if Select All menu item is there - if so, use it
  285.     theMenuItem := _match ([menuItem t:'Select All']!,1);
  286.     if (theMenuItem) begin
  287.         if (theMenuItem.e) begin
  288.             theMenuName := theMenuItem.m;
  289.             theMenuName := theMenuName.t;
  290.             if (SelectMenuItem('Select All',theMenuName))
  291.                 return(1);    # just return to abort routine
  292.         end;
  293.     end;
  294.     
  295.     # if we get to here, there was no 'Select All' menu item or it couldn't
  296.     # be selected - at this point, do it manually.
  297.     ScrollBarList := GetVHScrollBars();            # Save current position of scrollbar
  298.     Vertical := ScrollBarList[1].s;
  299.     
  300.     Vertical_X := Vertical[1];
  301.     Vertical_Y := Vertical[2];
  302.     
  303.     ScrollWindow('V',0,1);                        # Scroll to the top of file
  304.     MoveRelativeToWindow (5,30,1);
  305.     _click();
  306.     ScrollWindow('V',1,1);                        # Scroll to the bottom of file
  307.     
  308.     _pressKey ({ shiftKey });                    # Select from top to bottom of file
  309.     try match [window o:1 b:?Rect];
  310.     catch theError
  311.         ExceptionDispatcher(theError);
  312.     MoveRelativeToWindow (Rect[3]-Rect[1]-20,Rect[4]-Rect[2]-30,1);
  313.     _click();
  314.     _releaseKey ({ shiftKey });
  315.     
  316.     ScrollWindow('V',Vertical_X,Vertical_Y);    # Scroll back to original position
  317. end;
  318.  
  319.  
  320. #########################################################################
  321. #                RandomTextSelection(pSpecifier, pWindowInset)    
  322. #========================================================================
  323. # Author:        KTA
  324. # Description:    Matches the current document window, clicks in a random location,
  325. #                press the shiftkey, move to another random location and click.
  326. #                This will select all text between the two random points.
  327. # Parameters:    pSpecifier - window specifier.
  328. #                pWindowInset - inset into the window for the content region
  329. # Returns:        nothing
  330. # Example:        RandomTextSelection();
  331. #========================================================================
  332. # History:
  333. #    KTA        1/12/94        Created
  334. #    ML        11/29/94    Added Exception Handling support
  335. #    ML        12/12/94    Removed gLogLevel, replace w/gDisableAllLogging
  336. #   JC       2/6/96     Changed theWind.r to theWind.b. 
  337. #   JC       2/6/96     Changed pWindowInset := {0,22,22,22} to pWindowInset := {0,0,22,22}.
  338. #########################################################################
  339. TASK RandomTextSelection(pSpecifier := 0, pWindowInset := {0,0,22,22})
  340. begin
  341.     theWind := findWindow(pSpecifier);
  342.     theRect := theWind.b;    # Bounds does not include the title bar for the Top point in {Left, Top, Right, Bottom}
  343.     if (theRect)
  344.     begin
  345.         Pointlist := getXYRandom(pWindowInset,theRect,2);
  346.         #println "The Pointlist - '{Pointlist}'/ the theRect '{theRect}'";
  347.     
  348.         StartPoint := Pointlist[1];
  349.         EndPoint := Pointlist[2];
  350.         
  351.         tempgDisableAllLogging := global gDisableAllLogging;
  352.         global gDisableAllLogging := 1;
  353.         
  354.         MoveRelativeToWindow(StartPoint[1], StartPoint[2],1,2);    # Move to StartPoint and click
  355.         _pressKey ({shiftkey});
  356.         MoveRelativeToWindow(EndPoint[1], EndPoint[2],1,2);    # Move to EndPoint and click
  357.         _releaseKey ({shiftkey});
  358.         
  359.         global gDisableAllLogging := tempgDisableAllLogging;
  360.         
  361.         logStr("Selected the region enclosed in the rect '{Pointlist}'");
  362.     end;
  363. end; # RandomTextSelection()